/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package utils;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.swing.JToggleButton;

/**
 *
 * @author chocoseb
 */
public class DateSelection {

    private Calendar _date = new GregorianCalendar();
    private boolean _selected = false;
    private ChocoCalendar _cal;
    private JToggleButton _btn;

    public DateSelection(Calendar _date,JToggleButton btn, ChocoCalendar parent) {
        this._date.setTime(_date.getTime());
        _cal = parent;
        _btn = btn;
    }

    public Calendar getDate() {
        return _date;
    }

    public void setDate(Calendar _date) {
        this._date = _date;
    }

    public boolean isSelected() {
        return _selected;
    }

    public void setSelected(boolean _selected) {
        this._selected = _selected;
    }
    
    public void select(){
        _selected = true;
        _btn.setSelected(true);
        if (_cal.getSelectedSelection() != null) {
            _cal.getSelectedSelection().unselect();
        }
    }
    
    public void unselect(){
        _selected = false;
        _btn.setSelected(false);
    }

    public void bindToToggleButton(JToggleButton btn){
        btn.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                select();
            }
        });
    }

    

}
